//
// Created by lijia on 2021/1/12.
//

#ifndef PERISCOPE_JOYSTICK_H
#define PERISCOPE_JOYSTICK_H

#include <stdint.h>
#include "stm32f1xx_hal.h"

#define JOYSTICK_DIR_NORTH 1u
#define JOYSTICK_DIR_SOUTH 2u
#define JOYSTICK_DIR_EAST 4u
#define JOYSTICK_DIR_WEST 8u

typedef struct {
	int16_t x;
	int16_t y;

	uint8_t direction;
} JoystickState;

typedef struct {
	int16_t xBias;
	int16_t yBias;
	int16_t xDeadBand;
	int16_t yDeadBand;
	uint16_t xNeutral;
	uint16_t yNeutral;
} JoystickConfig;

extern void joystick_init(ADC_HandleTypeDef *);

extern void joystick_calibrate_neutral();

extern uint8_t joystick_is_calibrating();

extern const JoystickState *joystick_get();

extern void joystick_tick();

#endif //PERISCOPE_JOYSTICK_H
